{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# 函数式编程：程序都是由函数组成的，可以把函数当成参数和返回值\n",
    "- lanbda表达式（匿名函数）\n",
    "\t- 语法格式 x = lambda 参数1，参数2，..,参数n : 运算内容       调用  x(参数1，参数2,...,参数n)\n",
    "\t- 匿名函数没有返回值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# lambda表达式的应用举例\n",
    "func = lambda x,y,z : x+y+z\n",
    "print(func(1,2,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1+2\nNone\n3\n"
     ]
    }
   ],
   "source": [
    "# 把字符串当作代码执行的函数exec()：没有返回值 eval():有返回值\n",
    "a = \"1+2\"\n",
    "print(a)\n",
    "print(exec(a))\n",
    "print(eval(a))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 把函数当作参数使用的函数就是高阶函数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# filter函数：对一组数据进行过滤操作，符合条件的组成新的列表返回\n",
    "- filter必须要有参数，且返回的是一个bool值\n",
    "- 函数的返回值是一个可迭代的对象，需要用for循环来输出可视内容\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<filter object at 0x0000023DED18B668>\n[2, 4]\n"
     ]
    }
   ],
   "source": [
    "def f(x):\n",
    "    return x%2 == 0\n",
    "a = [1,2,3,4]\n",
    "b = filter(f,a)\n",
    "print(b)\n",
    "print([i for i in b])\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
